home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006051A < prev    next >
Text File  |  1992-06-02  |  2KB  |  86 lines

  1. LISTING FOUR
  2.  
  3. #include    "channel.hpp"
  4.     
  5. #define MAX_CHANNELS    36        // # of lines
  6.  
  7. // Global Variables
  8. int Hw_int;                   // hardware interrupt
  9. int Int_level;               // software interrupt
  10. CHANNEL Channel[MAX_CHANNELS];
  11.  
  12. // Local Prototypes
  13. static int wait_for_event(EVTBLK *evtp);
  14. static void process_lines();
  15. static int init_card();
  16.  
  17. main()
  18. {
  19.     if(!init_card()) {
  20.         puts("Couldn't initialize card!");
  21.         exit(0);
  22.     }
  23.     for (int line=0; line<MAX_CHANNELS; line++)
  24.         Channel[line].prep(line);
  25.     process_lines();
  26.     stopsys();
  27. }
  28.  
  29.  
  30. void process_lines()
  31. {
  32.     // event data block for speech card "events"
  33.     EVTBLK evtblk;       
  34.  
  35.     for(;;) {
  36.         // wait for a speech card to generate event
  37.            if (wait_for_event(&evtblk)!=0)
  38.             break;
  39.  
  40.         // get a pointer to channel for this event
  41.         CHANNEL *ch = &Channel[evtblk.devchan];
  42.         ch->cmplt_state(evtblk.evtcode);
  43.  
  44.         // begin new state and check for error
  45.         int errcode;
  46.         if ((errcode = ch->begin_state()) != 0)
  47.             printf("Error %d\n", errcode);
  48.     }
  49. }
  50.  
  51.  
  52. int init_card()
  53. {
  54.     unsigned int channels = 0;     // phone lines found
  55.     Int_level = getvctr();    // get software interrupt
  56.  
  57.  
  58.     // if card found, start the dialogic system with
  59.     // correct interrupt level, with event queuing 
  60.     // enabled, no extra buffers allocated, and
  61.     // store the number of lines in 'channels'
  62.     if(Int_level) {
  63.         stopsys();
  64.         startsys(Hw_int, SM_EVENT, 0, 0, &channels);
  65.     }
  66.     return channels;    
  67. }
  68.  
  69.  
  70. // Return 0 if card generates event or -1 
  71. // if ESC key was pressed.
  72. int wait_for_event(EVTBLK *evtp)
  73. {
  74.     for(;;) {
  75.         // check to see if a key has been pressed
  76.            while (bioskey(1))  {
  77.             // exit if ESC was pressed
  78.               if (bioskey(0) == 0x11b) 
  79.                 return -1;
  80.         }
  81.            if (gtevtblk(evtp) == -1)
  82.             break;
  83.     }
  84.     return 0;
  85. }
  86.